<?php
/**
 * 扫描es 数据索引
 */
header("content-type:text/plain;charset=utf8");
require './include/config.php';
require './include/CurlMulti.php';

// 存储数据

$index = 'baidu_xiaoqu2';
$type = 'xiaoqu';
$es_bulk = $conf['es']['hosts'].'/_bulk';
$es_url = $conf['es']['hosts'].'/'.$index.'/'.$type.'/_search';

try {
    
    $post = '{"size":1000,"_source":{"includes":["name","addr","baidu_geo"]},
     "query":{"bool":{"must":[
         {"terms":{"cla.cla_id":["24","25"]}},
         {"range":{"diPointX":{"gt":1291223918,"lt":1305380716}}},
         {"range":{"diPointY":{"gt":479371047,"lt":489585446}}},
         {"wildcard":{"std_tag":"*房地产*"}}
    ]}}}';
    $res = fly_curl($conf['es']['hosts'] . '/' . $index . '/_search?search_type=scan&scroll=1m',$post) ;
    $res = json_decode($res, true);
    $count = 0;
    while ($page = fly_curl($conf['es']['hosts'] . '/_search/scroll?scroll=1m&&scroll_id=' . $res["_scroll_id"])) {
        $page = json_decode($page, true);
        $count += count($page["hits"]["hits"]);
        //echo "读取 [",$index,"] 索引数据 ...", "数据读取 ",$count,"/",$page["hits"]["total"]," ... 进度 ",round($count/$page["hits"]["total"] * 100, 3),"%","\n";
        foreach ($page["hits"]["hits"] as $item) {
            echo $item["_source"]["name"] ,"\t",$item["_source"]["addr"],"\t",json_encode($item["_source"]["baidu_geo"]), "\n";
        }
    }
    
} catch(Exception $e) {
    echo '<pre>';
    var_dump($e->getCode(), $e->getLine(), $e->getMessage());
    echo '</pre>';
}


